package org.summer.netty;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;

import java.nio.charset.StandardCharsets;

public class TestByteBuf {
    public static void main(String[] args) {


    }

    private static void testSlice() {
        ByteBuf buffer = ByteBufAllocator.DEFAULT.buffer(10);

        buffer.writeBytes(new byte[]{1,2,3,4,5,6,7,8,9,10});


        ByteBuf slice = buffer.slice(0, 5);

        slice.setByte(0,100);

        System.out.println(buffer.getByte(0));
        System.out.println(slice.getByte(0));
    }

    private static void baseMethod() {
        ByteBuf buffer = ByteBufAllocator.DEFAULT.buffer();

        System.out.println(buffer);
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < 300; i++) {
            stringBuilder.append("A");
        }

        buffer.writeBytes(stringBuilder.toString().getBytes(StandardCharsets.UTF_8));

        System.out.println(buffer);
    }
}
